import { createStore } from 'vuex'
import {login , checkLogin} from '../api/index.js'
/**
 * 创建仓库和导出
 */
export default createStore({
    state: {
        isLogin:null,
        info:null,
    },
    mutations: {
        changeIsLogin(state, bool) {
            state.isLogin = bool;
        },
        changeInfo(state, payload) {
            state.info = payload;
        }
    },
    actions: {
        async changeIsLoginAsync({commit}) {
            let bool = false;
            let  {code}  =await checkLogin()
            if( +code === 0) bool = true;
            commit('changeIsLogin', bool)

        },
        async changeInfoAsync({commit}) {
            
            let  {code , data}  =await checkLogin()
            if( +code === 0){
                commit('changeInfo', data)

            }
            

        }
    },

})